<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />
        <title>Show Employee</title>
    </head>
    <body>
        <div class="undernav">
          <span class="menuButton"><g:link class="createEmployee" action="create">New Employee</g:link></span>
        </div>
        <div class="body">
<div class="mode">
              <span style="font-weight:bold; padding-right:10px">
              <g:if test="${session.mode == null || session.mode.equalsIgnoreCase('sandbox')}">
                Sandbox mode
              </g:if>
              <g:else>
                Budget mode
              </g:else>
                </span>
            </div>
            <h1>Show Employee</h1>
            <g:if test="${flash.message}">
              <div class="message">${flash.message}</div>
            </g:if>
            <div style="width: 100%;">
              <table>
                <tr>
                  <td>
                    <table>
                      <tr>
                        <td>
                          <div class="dialog">
                            <h2 style="margin-left:8px;">Person details</h2>
                            <table width="100%" style="border:none;">
                                <tbody>
                                    <tr>
                                      <td valign="top" class="name"><b>Title:</b> ${fieldValue(bean:employeeInstance, field:'title')}</td>
                                    </tr>
                                    <tr class="prop">
                                      <td valign="top" class="name"><b>Name:</b> ${fieldValue(bean:employeeInstance, field:'firstName')} ${fieldValue(bean:employeeInstance, field:'lastName')}</td>
                                    </tr>
                                    <tr class="prop">
                                      <td valign="top" class="name"><b>Date of Birth</b>: <g:formatDate date="${employeeInstance.dob}" format="yyyy-MM-dd"/></td>
                                    </tr>
                                    <tr>
                                      <td valign="top" class="name"><b>Address:</b> ${fieldValue(bean:employeeInstance, field:'street')}, ${fieldValue(bean:employeeInstance, field:'zipCode')} ${fieldValue(bean:employeeInstance, field:'city')}</td>
                                    </tr>
                                    <tr>
                                      <td valign="top" class="name"><b>Email:</b> ${fieldValue(bean:employeeInstance, field:'email')}</td>
                                    </tr>
                                    <tr>
                                      <td valign="top" class="phoneNumber"><b>Phone number:</b> ${fieldValue(bean:employeeInstance, field:'phoneNumber')}</td>
                                    </tr>
                                </tbody>
                            </table>
                          </div>
                        </td>
                        <td>
                          <div class="dialog" style="float:left; margin-left:85px;">
                            <h2 style="margin-left:8px;">Work details</h2>
                            <table width="100%" style="border:none;">
                              <tbody>
                                <tr class="prop">
                                  <td valign="top" class="name"><b>Salary:</b> ${fieldValue(bean:employeeInstance, field:'salary')}</td> <!--Same as employeeInstance?.salary but often used for srings  -->
                                </tr>
                                <tr>
                                  <td valign="top" class="name"><b>Percentage Work:</b> ${fieldValue(bean:employeeInstance, field:'percentageWork')} %</td>
                                </tr>
                                <tr>
                                  <td valign="top" class="name"><b>Hours Per Year:</b> <g:formatNumber number="${employeeInstance.workingHoursPerYear}" format="###"/> h</td>
                                </tr>
                                <tr class="prop">
                                <td valign="top" class="name"><b>Hired By:</b> ${employeeInstance?.hiredBy?.name}
                                </td>
                                </tr>
                              </tbody>
                            </table>
                       
                          </div>
                        </td>
                      </tr>
                    </table>
                    <table  style="margin-top:8px;">
                      <tr>
                        <td>
                          <div class="dialog">
                            <h2 style="margin-left:8px;">Project details</h2> <!--  margin-top:25px; -->
                              <table width="100%" style="border:none;">
                                 <thead>
                                  <tr>
                                    <!--Admin creating accounts shall be able to fill in nr of hours worked per year OR percent per year -->
                                    <th>Working total (% per year)</th>  <!--inputHours/totalHours -->
                                    <th>Working hours (per year)</th>    <!--inputHours -->
                                    <th>Work not assigned</th>           <!--(total-actualHours)/ -->
                                    <th>Hours not assigned</th>          <!--actualHours -->
                                  </tr>                                  
                                </thead>                                 <!--to add picture      <img src="url(../images/skin/users.png)" /> -->
                                <tbody>
                                 <tr>       <!-- rad nr -->
                                   <td>
                                      <tr>
                                        <td>${employeeInstance.percentageWork}%</td>     <!--employeeInstance.percentageWork OR getPercentageWorkingFrom(hour) -->
                                        <td>${employeeInstance.percentageWork/100*employeeInstance.getWorkingHoursPerYear()}</td>     <!--employeeInstance.percentageWork*getWorkingHoursPerYear OR hour -->
                                        <td>${(employeeInstance.percentageWork/100*employeeInstance.getWorkingHoursPerYear()-employeeInstance.actualWorkingHoursPerYear())/(employeeInstance.percentageWork/100*employeeInstance.getWorkingHoursPerYear())}</td>   <!--(above-employeeInstance.actualWorkingHoursPerYear())/above-->
                                        <td>${(employeeInstance.percentageWork/100*employeeInstance.getWorkingHoursPerYear()-employeeInstance.actualWorkingHoursPerYear())}</td>     <!--2above-employeeInstance.actualWorkingHoursPerYear() -->
                                      </tr>
                                   </td>
                                 </tr>
                                </tbody>
                                

                                <thead>                                  <!--totalHours = 1700 or 1732 (getWorkingHoursPerYear), inputHours = hours input when employee created (getPercentageWorkingFromHours()), actualHours = sum of hours in list of project (actualWorkingHoursPerYear())(-->
                                  <tr>
                                    <th>Active in Project</th>
                                    <th>Hours</th>
                                    <th>Percentage</th>
                                  </tr>
                                </thead>
                                <tbody>
                                 <tr>       <!-- rad nr -->
                                   <td>     <!-- col nr -->
                                    <g:each var="m" in="${whoaList}">       <!-- for every element (m, a whoa) in the list (whoaList) -->
                                      <g:if test="${ModeAccess.isAvailableInCurrentMode(session.mode,m?.member?.mode)}">
                                        <tr>
                                          <td><g:link action="show" controller="project" id="${m?.worksInProject?.id}">${m?.worksInProject?.name} </g:link></td>
                                          <td>${m?.hours}</td>
                                          <td>${(m?.hours/(employeeInstance.percentageWork/100*employeeInstance.getWorkingHoursPerYear()))}%</td>  <!-- Percentage calculated from worked hours in a specific project in relation to total worked hours for that year -->
                                        </tr>
                                            <!-- <g:formatNumber number="${m?.member?.salary}" format="SEK ##,##0" />-->
                                      </g:if>
                                    </g:each>
                                   </td>
                                 </tr>
                                </tbody>
                            </table>
                          </div>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
                 <tr>
                  <td>
                    <div class="buttons">
                      <g:form>
                          <input type="hidden" name="id" value="${employeeInstance?.id}" />
                          <span class="button"><g:actionSubmit class="editEmployee" value="Edit" /></span>
                          <span class="button"><g:actionSubmit class="deleteEmployee" onclick="return confirm('Are you sure?');" value="Delete" /></span>
                      </g:form>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
        </div>
    </body>
</html>
